#ifndef CONTACTMANAGER_H
#define CONTACTMANAGER_H

#include <vector>
#include <map>
#include <algorithm>

#include <wx/tokenzr.h>
#include <wx/fileconf.h>

#include "MsnContact.h"

typedef std::map<wxString, MsnContact*> ContactMap; //<passport, MsnContact*>
typedef std::vector<MsnGroup*> GroupList;

class ContactManager
{
typedef std::vector<wxString> StringList;

private:
    GroupList groupList;
    ContactMap contactMap;

    wxArrayString recentList;

	wxString homePath;
    
    wxFileConfig* contactConfig;
    wxFileConfig* contactExConfig;

public:
    ContactManager(const wxString& home);
    ~ContactManager();

public:
    void LoadContact();
    void SaveContact();

    void LoadContactEx();
    void SaveContactEx();

    void Reset();

public:
    GroupList& GetGroupList(){return groupList;}
    ContactMap& GetContactMap(){return contactMap;}
    int GetGroupCount(){return groupList.size();}
    MsnGroup* GetGroup(int index){return groupList[index];}
    MsnGroup* GetGroup(const wxString& groupID);
	void AddGroup(MsnGroup* group);
    void DeleteGroup(const wxString& groupID);
    void UpdateGroupName(const wxString& id, const wxString& name);

public:
    MsnContact* GetContact(const wxString& passport);
    MsnContact* GetContactByID(const wxString& id);

    void AddContact(MsnContact* contact);
	void RemoveContact(const wxString& contactID);

	void AddContactToGroup(const wxString& contactID, const wxString& groupID);
	void RemoveContactFromGroup(const wxString& contactID, const wxString& groupID);

//	void AddContactToList(const wxString& contactID, const wxString& list);
//	void RemoveContactFromList(const wxString& contactID, const wxString& list);

    void UpdateContactStatus(const wxString& passport, const wxString& status);
    void UpdateContactNickname(const wxString& passport, const wxString& alias);
    void UpdateContactName(const wxString& passport, const wxString& name);

    void AddRecentContact(const wxString& contact);
    wxArrayString GetRecentContactList(){return recentList;}

    wxArrayString GetOnlineContactList();

};


#endif
